/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package SIC115;

import Modelos.Empresa;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 *
 * @author Randy
 */
public class MainApp extends Application {
    
    private Stage primaryStage;
    private BorderPane rootLayout;
    private Empresa empresa;
    
    @Override
    public void start(Stage stage) throws Exception {
       this.primaryStage = stage;
       this.primaryStage.setTitle("ContaProject");
       InitRootLayout();
       EmpresaInformacion();
    }
    
    public MainApp(){
        
    }
    
    public void InitRootLayout(){
        try {
            FXMLLoader cargador = new FXMLLoader();
            cargador.setLocation(MainApp.class.getResource("RootLayout.fxml"));
            rootLayout = (BorderPane) cargador.load();
            
            Scene escena = new Scene(rootLayout);
            primaryStage.setScene(escena);
            RootLayoutController controlador = cargador.getController();
            controlador.setMainApp(this);
            
            primaryStage.show();
        } catch (IOException ex) {
            Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
        }
                
    }
    
    public void EmpresaInformacion(){
       
        try {
            FXMLLoader cargador = new FXMLLoader();
            cargador.setLocation(MainApp.class.getResource("DatosEmpresa.fxml"));
            AnchorPane EmpresaInformacion = (AnchorPane) cargador.load();
            
            rootLayout.setCenter(EmpresaInformacion);
            
            DatosEmpresaController controlador = cargador.getController();
            controlador.setMainApp(this);
        } catch (IOException ex) {
            Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
        }
            
       
    }
    
    public void registrarTransaccion(){
        try {
            FXMLLoader cargador = new FXMLLoader();
            cargador.setLocation(MainApp.class.getResource("Transaccion.fxml"));
            AnchorPane RTransaccion = (AnchorPane) cargador.load();
            
            Stage EscenarioRtran = new Stage();
            EscenarioRtran.setTitle("Registro de Transaccion");
            EscenarioRtran.initModality(Modality.WINDOW_MODAL);
            EscenarioRtran.initOwner(primaryStage);
            Scene EscenaRTtran = new Scene(RTransaccion);
            EscenarioRtran.setScene(EscenaRTtran);
            
            TransaccionController controlador = cargador.getController();
            controlador.setDialogoStage(EscenarioRtran);
            
            EscenarioRtran.showAndWait();
        } catch (IOException ex) {
            Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    
    public Stage getPrimaryStage() {
        return primaryStage;
    }
    
    

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
}
